# rocksdb.cmake
# 本文件包含着从外部导入 RocksDB 所需要的信息

SET(ROCKSDB_SOURCES_DIR "${LIB_SOURCE_DIR}/extern_rocksdb" CACHE PATH "Path to RocksDB sources")
SET(ROCKSDB_INCLUDE_DIR "${LIB_INCLUDE_DIR}" CACHE PATH "rocksdb include directory." FORCE)
SET(ROCKSDB_LIBRARIES "${LIB_INSTALL_DIR}/librocksdb.a" CACHE FILEPATH "rocksdb include directory." FORCE)

ExternalProject_Add(
        extern_rocksdb
        GIT_REPOSITORY https://github.com/facebook/rocksdb.git
        URL https://github.com/facebook/rocksdb/archive/refs/tags/v9.7.4.tar.gz
        CMAKE_ARGS
        -DCMAKE_INSTALL_PREFIX=${LIB_INSTALL_PREFIX}
        -DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}
        -DCMAKE_BUILD_TYPE=${LIB_BUILD_TYPE}
        BUILD_COMMAND make
)

ADD_DEPENDENCIES(extern_rocksdb snappy gflags zlib lz4)
ADD_LIBRARY(rocksdb STATIC IMPORTED GLOBAL)
SET_PROPERTY(TARGET rocksdb PROPERTY IMPORTED_LOCATION ${ROCKSDB_LIBRARIES})
ADD_DEPENDENCIES(rocksdb extern_rocksdb)